package com.zhaopin.effectivejava;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

public class Test {


    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {

        //List<Class<?>> constructorArgTypes, List<Object> constructorArgs
        //constructor = type.getDeclaredConstructor(constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));

        //constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));

        Class<User> userClass = User.class;

        List<Class<String>> constructorArgTypes = new ArrayList<>();
        Class<String> stringClass1 = String.class;
        Class<String> stringClass2 = String.class;
        constructorArgTypes.add(stringClass1);
        constructorArgTypes.add(stringClass2);
        List<String> constructorArgs = new ArrayList<>();
        String age = "23";
        String name = "LiLei";
        constructorArgs.add(age);
        constructorArgs.add(name);


        Constructor<User> declaredConstructor = userClass.getDeclaredConstructor(constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));

        User user = declaredConstructor.newInstance(constructorArgs.toArray(new Object[2]));
        System.out.println(user);


    }
}
